package com.xuhuan.server.result;

import java.util.HashMap;

/**
 * @Author huan.xu
 * @Date 2022/6/13 15:03
 * @Description 统一返回结果
 */
public class RequestResult<T>{

    /**
     * 错误消息
     */
    private String message;
    /**
     * 消息代码
     */
    private String resultcode;
    /**
     * 数据
     */
    private T data;
    public static final String FAIL_CODE = "-1";
    public static final String SUCCESS_CODE = "0";

    public RequestResult() {
        this.message = null;
        this.data = null;
        this.resultcode = "0";
    }

    public RequestResult(T data) {
        this.message = null;
        this.resultcode = "0";
        this.data = data;
    }

    public static <T> RequestResult<T> success() {
        RequestResult<T> requestResult = new RequestResult();
        requestResult.setResultcode("0");
        return requestResult;
    }

    public static <T> RequestResult<T> success(T data) {
        RequestResult<T> requestResult = new RequestResult();
        requestResult.setResultcode("0");
        requestResult.setData(data);
        requestResult.setData(data);
        return requestResult;
    }

    public static <T> RequestResult<T> fail(String resultCode, String message) {
        RequestResult<T> requestResult = new RequestResult();
        requestResult.setResultcode(resultCode);
        requestResult.setMessage(message);
        return requestResult;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getResultcode() {
        return resultcode;
    }

    public void setResultcode(String resultcode) {
        this.resultcode = resultcode;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
